package com.project.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author lyl
 * description:
 */
@Controller
@RequestMapping("user")
public class UserController {

    /**
     * 形如/user/del/1的url由当前方法进行处理
     * 将url中的1赋值于userId变量，然后将userId变量的值赋予形参变量userId
     *
     * @param userId
     * @return
     */
    @RequestMapping("del/{userId}")
    public void del(@PathVariable("userId") int userId, HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().println("userId=" + userId);
    }

    @RequestMapping("cutPage")
    public void cutPage(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, HttpServletResponse response) throws IOException {
        response.getWriter().println("pageNo=" + pageNo);
    }
}
